#pragma once

#include "DeviceInfo.h"

using namespace System;
using namespace System::Threading;
using namespace Microsoft::Robotics::Hardware::DAC;
using namespace System::Security;
using namespace System::Security::Permissions;

namespace Microsoft
{
    namespace Robotics
    {
        namespace ManagedBulkUsb
        {
            ref class Device;

            /// <summary>
            /// Represents an async operation on WinUsb device
            /// </summary>
			private ref class DeviceAsyncEventArgs : public AsyncEventArgs, public IDisposable
            {
			public:
				// destructor
				~DeviceAsyncEventArgs();

            internal:
                // Constructor
                DeviceAsyncEventArgs(Device^ transport, array<Byte>^ buffer, DeviceInfo_t* pdi);


                // Get the native overlapped structure used for I/O
                LPOVERLAPPED GetNativeOverlapped() { return (LPOVERLAPPED)pNativeOverlapped; }

                // The native device information currently associated this operation. Is NULL
                // when the async operation is not in progress.
                DeviceInfo_t* pdi;

            private:
                // Thread-pool callback when the async operation completes
                void OnCompleted(Object^ state, bool timedOut);

                // Reference to the device
                Device^ device;
                // The wait handle that signals when I/O is done
                WaitHandle^ handle;
                // Get the thread-pool to wait on our behalf.
                RegisteredWaitHandle^ waitHandle;

                // The CLR overlapped structure.
                Overlapped^ overlapped;

                // The native overlapped structure
                NativeOverlapped* pNativeOverlapped;

            };
        }
    }
}
